﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using Model;
using BLL;
using System.Data;

public partial class Spa_Index : WeiPage
{
    PersonInfoBO pbo = new PersonInfoBO();
    MembershipCardBO mbo = new MembershipCardBO();
    TicketBO tbo = new TicketBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["code"] != null)
            {
                try
                {
                    string url = string.Format(@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + GetAppid() + "&secret=" + GetSecret() + "&code={0}&grant_type=authorization_code", Request.QueryString["code"].ToString());
                    string token = PostRequest(url);
                    if (token.Contains("7200"))
                    {
                        string[] b = token.Split('\"');
                        Session["FromUserName"] = b[13];
                        Session["ToUserName"] = "wx8ecea9aaa3d6162b";
                    }
                }
                catch (Exception)
                {

                }
            }
          
            //DataSet ds = mbo.QCount();
            //if (ds != null)
            //{
            //    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            //    {

            //        qcount.InnerText = ds.Tables[0].Rows[0][0].ToString();
            //        if (Convert.ToInt32(ds.Tables[0].Rows[0][0]) > 0)
            //        {
            //            qcount.Visible = true;

            //        }
            //        else { qcount.Visible = false; }
            //    }

            //}


            if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
            {
                string user = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
                string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
                Session["FromUserName"] = user;
                Session["ToUserName"] = user2;

                List<Ticket> list = tbo.GetMyTicketIndex(user);
                qcount.InnerText =list.Count.ToString();
                if (list.Count > 0)
                {
                    qcount.Visible = true;

                }
                else { qcount.Visible = false; }

                PersonInfo p = pbo.GetModel(user);
                if (p != null)
                {
                    jf.InnerHtml = "积分：" + p.SurplusIntegral + " ";
                    si_DispMember_obService s1 = new si_DispMember_obService();
                    dt_DispMember_req w1 = new dt_DispMember_req();
                    w1.ZTYPE = "0101";
                    w1.MOB_NUMBER = p.Phone;
                    dt_DispMember_res dt1 = s1.si_DispMember_ob(w1);
                    if (dt1.ZCRMT316 != null)
                    {
                        jf.InnerHtml = "积分：" + Convert.ToInt32(dt1.ZCRMT316[0].ZCCUR_POINT) + " ";
                    }
                    hyk.Visible = false;
                }
                else
                {
                    hyk.Visible = true;
                    //tr1.Visible = false;
                    //tr2.Visible = false;
                    //tr3.Visible = true;
                    //tr4.Visible = true;
                    //Response.Redirect("weixinreg2.aspx");
                }
            }
            //Customer();
        }

    }
    public void Customer()
    {
        AllDAL sap = new AllDAL();
        si_DispMember_obService s = new si_DispMember_obService();
        dt_DispMember_req w = new dt_DispMember_req();
        w.ZTYPE = "0101";
        //w.NAME1_TEXT = "刘志刚";
        //w.BPEXT = "8001627";
        //IFormatProvider ifp = "{0:yyyy-MM-dd}";
        //string day = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
        string day = "1990-01-01";
        w.ZLAST_CHG_DATE = DateTime.Parse(day);

        w.ZLAST_CHG_DATESpecified = true;
        dt_DispMember_res dt = s.si_DispMember_ob(w);

        if (dt.ZCRMT316 != null)
        {
            foreach (var item in dt.ZCRMT316)
            {
                int add = sap.CustomerAdd(new Model.SAP_CUSTOMER
                        {
                            //CLIENT = item.clien
                            TYPE = item.TYPE,
                            //CREATED_AT = item.
                            BPEXT = item.BPEXT,
                            NAME_LAST = item.NAME_LAST,
                            NAME_FIRST = item.NAME_FIRST,
                            NAME1_TEXT = item.NAME1_TEXT,
                            ZTITLE = item.ZTITLE,
                            NICKNAME = item.NICKNAME,
                            NAMEMIDDLE = item.NAMEMIDDLE,
                            NAMCOUNTRY = item.NAMCOUNTRY,
                            REGION = item.REGION,
                            TRANSPZONE = item.TRANSPZONE,
                            XSEX = item.XSEX,
                            BIRTHDT = item.BIRTHDT.ToString(),
                            JOBGR = item.JOBGR,
                            BUPA_IDTYPE_PRS = item.BUPA_IDTYPE_PRS,
                            IDNUMBER = item.IDNUMBER,
                            PSTREET = item.PSTREET,
                            CSTREET = item.CSTREET,
                            POST_CODE1 = item.POST_CODE1,
                            CPOST_CODE1 = item.CPOST_CODE1,
                            TEL_NUMBER = item.TEL_NUMBER,
                            MOB_NUMBER = item.MOB_NUMBER,
                            SMTP_ADDR = item.SMTP_ADDR,
                            QQ = item.QQ,
                            MSN = item.MSN,
                            CTEL_NUMBER = item.CTEL_NUMBER,
                            CMOB_NUMBER = item.CMOB_NUMBER,
                            CFAX_NUMBER = item.CFAX_NUMBER,
                            CSMTP_ADDR = item.CSMTP_ADDR,
                            RE_BPEXT = item.RE_BPEXT,
                            REG_DATE = item.REG_DATE.ToString(),
                            LOGINNAME = item.LOGINNAME,
                            LOGINPASS = item.LOGINPASS,
                            DEPTID = item.DEPTID,
                            EMPID = item.EMPID,
                            vkorg = item.VKORG,
                            dis_channel = item.DIS_CHANNEL,
                            division = item.DIVISION,
                            ZC001 = item.ZC001,
                            ZC002 = item.ZC002,
                            ZC003 = item.ZC003,
                            ZC004 = item.ZC004,
                            ZC008 = item.ZC008,
                            ZC005 = item.ZC005,
                            ZC007 = item.ZC007,
                            ZA001 = item.ZA001,
                            ZA002 = item.ZA002,
                            ZA003 = item.ZA003,
                            ZA004 = item.ZA004,
                            ZA005 = item.ZA005,
                            ZA006 = item.ZA006,
                            ZB002 = item.ZB002,
                            ZB003 = item.ZB003,
                            ZC009 = item.ZC009,
                            ZC010 = item.ZC010,
                            ZC011 = item.ZC011,
                            ZC012 = item.ZC012,
                            ZC013 = item.ZC013,
                            ZC014 = item.ZC014,
                            ZC015 = item.ZC015,
                            ZC016 = item.ZC016,
                            ZC017 = item.ZC017,
                            ZC018 = item.ZC018,
                            ZC019 = item.ZC019,
                            ZC020 = item.ZC020,
                            ZC021 = item.ZC021,
                            ZC023 = item.ZC023,
                            ZTIER = item.ZTIER,
                            ZCCUR_POINT = item.ZCCUR_POINT.ToString(),
                            Z_POINT = item.Z_POINT.ToString()
                        });

            }
        }
    }
}